/**
 * 右侧导航
 */
define(function (require) {
    'use strict';
    var $ = require('jquery');
    var util = require('util');
    var _ = require('underscore');
    var permission = require('permission');
    var NavManager = require('/static_public/public_menu/navManager');
    var environment = require('environment');
    var qmyxHost = environment.qmyx;
    require('/static_public/js/token');
    permission.getData(function(permissionCodes){
        var url = qmyxHost + '/api/index.php?r=ydxs/sale-report/is-new';
        $.ajax({
            url:url,
            cache : false,
            dataType:'jsonp',
            jsonp:'callback',
            data : {
                token : util.getToken()
            },
            success:function(data) {
                if(data.retCode === 0){
                    if(_.contains(permissionCodes.nav,'50020401')){
                         if(data.data.is_new === 1){
                            $('#daily_report a').attr('href',qmyxHost+'/ydxs_static/page/statistical/report_form.html');
                            $('#performance_report a').attr('href', qmyxHost+'/ydxs_static/page/initialize/performance_statistics.html');
                        }
                    }
                }else{
                    util.alert(data.errMsg);
                }
            },
            error : function(jqXHR, textStatus, errorThrown){
                console.error(errorThrown);
            },
            timeout:10000
        });
    });
    return {
        init: function () {
            new NavManager($('#nav'), [
                {
                    'id': 'menu_project',
                    'code': '',
                    'name': '返回掌上售楼处',
                    'level': 1,
                    'iconCls': 'icon-return',
                    'cls': 'c-mvp only-mvp mvp-qdgj',
                    'url': [environment.qmyx + '/page/palm_sales/index.shtml'],
                    'children': null
                },
                {
                    'id': 'menu_ditch_manage',
                    'code': '',
                    'name': '渠道管理',
                    'level': 1,
                    'iconCls': 'icon-ditchManage',
                    'url': '',
                    'cls': 'icon-fav',
                    'children': [
                        {
                            'id': 'menu_ditch_manage_5',
                            'code': '500701',
                            'name': '规则管理',
                            'level': 2,
                            'target': '_blank',
                            'url': [environment.qmyx + '/page/ditch/index.shtml?code=ruleSet']
                        },
                        {
                            'id': 'menu_ditch_manage_6',
                            'code': '500702',
                            'name': '判客分配',
                            'level': 2,
                            'target': '_blank',
                            'url': [environment.qmyx + '/page/ditch/index.shtml?code=guestAllot']
                        }
                    ]
                },
                {
                    'id': 'ywgl',
                    'name': '业务管理',
                    'code': '500203',
                    'level': 1,
                    'iconCls': 'icon-business',
                    'url': '',
                    'cls': 'icon-fav',
                    'children': [{
                        'id': 'cst_follow',
                        'name': '客户跟进管理',
                        'code': '50020304',
                        'level': 2,
                        'showInIframe': false,
                        'url': [environment.qmyx + '/ydxs_static/page/service_manage/customerFollow_manage.html']
                    }, {
                        'id': 'cst_assign',
                        'name': '客户分配',
                        'code': '50020305',
                        'level': 2,
                        'showInIframe': true,
                        'url': [environment.qmyx + '/page/customer_distribution/index.html',environment.mysrc + '/ydxs_static/page/proxy.ashx?code=cst_assign']
                    }]
                },
                {
                    'id': 'yun_callke',
                    'code': '503001',
                    'name': '云call客',
                    'level': 1,
                    'iconCls': 'icon-callke',
                    'url': '',
                    'cls': 'icon-fav',
                    'children': [
                        /*  {
                         'id': 'callke_menu_1',
                         'code': '',
                         'name': '案场参数配置',
                         'level': 2,
                         'url': ['/page/wangcaibao/call_setting.shtml']
                         },
                         {
                         'id': 'callke_menu_2',
                         'code': '',
                         'name': 'call客任务管理',
                         'level': 2,
                         'url': ['/page/wangcaibao/index.shtml']
                         },
                         {
                         'id': 'callke_menu_3',
                         'code': '',
                         'name': 'call客台账管理',
                         'level': 2,
                         'url': ['/page/wangcaibao/account_xike.shtml']
                         },*/
                        {
                            'id': 'callke_menu_4',
                            'code': '503001',
                            'name': '案场来电管理',
                            'level': 2,
                            'url': [environment.qmyx + '/page/wangcaibao/call_manage.shtml?token='+util.getToken()]
                        }
                    ]
                },
                {
                    'id': 'initSetting',
                    'name': '初始化设置',
                    'code': '500202',
                    'level': 1,
                    'iconCls': 'icon-initset',
                    'url': '',
                    'cls': 'icon-fav',
                    'children': [{
                        'id': 'paramsSetting',
                        'name': '参数设置',
                        'code': '50020203',
                        'level': 2,
                        'showInIframe': true,
                        'url': [environment.mysrc + '/ydxs_static/page/proxy.ashx?code=paramsSetting']
                    }, {
                        'id': 'erpi_nterface_set',
                        'name': 'ERP接口配置',
                        'code': '50020207',
                        'level': 2,
                        'showInIframe': true,
                        'url': [environment.mysrc + '/ydxs_static/page/proxy.ashx?code=erpi_nterface_set']
                    }, {
                        'id': 'sales_data_init',
                        'name': '数据初始化',
                        'code': '50020204',
                        'level': 2,
                        'showInIframe': true,
                        'url': [environment.mysrc + '/ydxs_static/page/proxy.ashx?code=sales_data_init']
                    }, {
                        'id': 'custom_page',
                        'name': '定制页面',
                        'code': '50020206',
                        'level': 2,
                        'showInIframe': true,
                        'url': [environment.mysrc + '/ydxs_static/page/proxy.ashx?code=custom_page']
                    }]
                }, {
                    'id': 'statistics',
                    'name': '统计分析',
                    'code': '500204',
                    'level': 1,
                    'iconCls': 'icon-analysis',
                    'cls': 'c-mvp has-ydxs icon-fav',
                    'url': '',
                    'children': [{
                        'id': 'daily_report',
                        'name': '案场日报',
                        'code': '50020401',
                        'level': 2,
                        'showInIframe': true,
                        'url': [environment.mysrc + '/ydxs_static/page/proxy.ashx?code=daily_report','/ydxs_static/page/statistical/report_form.html','/ydxs_static/page/initialize/parameter_settings.html']
                    }, {
                        'id': 'performance_report',
                        'name': '销售业绩',
                        'code': '50020402',
                        'level': 2,
                        'showInIframe': true,
                        'url': [environment.mysrc + '/ydxs_static/page/proxy.ashx?code=performance_report','/ydxs_static/page/initialize/performance_statistics.html']
                    }]
                },
                {
                    'id': 'cstSyncExcep',
                    'name': '客户同步监控',
                    'code': '500205',
                    'iconCls': 'icon-monitor',
                    'level': 1,
                    'url': [environment.mysrc + '/ydxs_static/page/proxy.ashx?code=cstSyncExcep'],
                    'children': null
                }
            ]);
        }
    };
});
